﻿namespace Bzure.Common.Composition
{
    using System;
    using System.Configuration;
    using System.Collections.Generic;

    /// <summary>
    /// Represents a configuration of a singular catalog.
    /// </summary>
    public class CatalogConfigurationElement : ConfigurationElement
    {
        #region Fields
        private const string NameAttribute = "name";
        private const string PathAttribute = "path";
        #endregion

        #region Methods
        /// <summary>
        /// Gets or sets the name of the catalog.
        /// </summary>
        [ConfigurationProperty(NameAttribute, IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)this[NameAttribute]; }
            set { this[NameAttribute] = value; }
        }

        /// <summary>
        /// Gets or sets the path of the catalog.
        /// </summary>
        [ConfigurationProperty(PathAttribute, IsRequired = true)]
        public string Path
        {
            get { return (string)this[PathAttribute]; }
            set { this[PathAttribute] = value; }
        }
        #endregion
    }
    public static class EnumerableExtensions
    {
        #region Methods
        /// <summary>
        /// Performs the given <see cref="Action{T}" /> on each item in the enumerable.
        /// </summary>
        /// <typeparam name="T">The type of item in the enumerable.</typeparam>
        /// <param name="items">The enumerable of items.</param>
        /// <param name="action">The action to perform on each item.</param>
        public static void ForEach<T>(this IEnumerable<T> items, Action<T> action)
        {
            foreach (T item in items)
                action(item);
        }
        #endregion
    }
}